<?php

/**
 * This is the model class for table "{{region}}".
 *
 * The followings are the available columns in table '{{region}}':
 * @property integer $region_id
 * @property string $region_code
 * @property string $region_name
 * @property string $parent_code
 * @property integer $level
 * @property string $region_alias
 * @property string $merge_name
 * @property string $phone_code
 * @property string $post_code
 * @property string $car_code
 * @property string $town_code
 * @property string $longitude
 * @property string $latitude
 * @property string $pinyin
 * @property string $initial_letter
 * @property string $first_letter
 */
class Region extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Region the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{region}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('region_code, region_name, parent_code, level', 'required'),
			array('level', 'numerical', 'integerOnly'=>true),
			array('region_code, initial_letter', 'length', 'max'=>16),
			array('region_name, region_alias', 'length', 'max'=>128),
			array('parent_code, longitude, latitude', 'length', 'max'=>32),
			array('merge_name', 'length', 'max'=>255),
			array('phone_code, post_code, car_code, town_code', 'length', 'max'=>8),
			array('pinyin', 'length', 'max'=>64),
			array('first_letter', 'length', 'max'=>1),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('region_id, region_code, region_name, parent_code, level, region_alias, merge_name, phone_code, post_code, car_code, town_code, longitude, latitude, pinyin, initial_letter, first_letter', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'region_id' => 'Region',
			'region_code' => 'Region Code',
			'region_name' => 'Region Name',
			'parent_code' => 'Parent Code',
			'level' => 'Level',
			'region_alias' => 'Region Alias',
			'merge_name' => 'Merge Name',
			'phone_code' => 'Phone Code',
			'post_code' => 'Post Code',
			'car_code' => 'Car Code',
			'town_code' => 'Town Code',
			'longitude' => 'Longitude',
			'latitude' => 'Latitude',
			'pinyin' => 'Pinyin',
			'initial_letter' => 'Initial Letter',
			'first_letter' => 'First Letter',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('region_id',$this->region_id);
		$criteria->compare('region_code',$this->region_code,true);
		$criteria->compare('region_name',$this->region_name,true);
		$criteria->compare('parent_code',$this->parent_code,true);
		$criteria->compare('level',$this->level);
		$criteria->compare('region_alias',$this->region_alias,true);
		$criteria->compare('merge_name',$this->merge_name,true);
		$criteria->compare('phone_code',$this->phone_code,true);
		$criteria->compare('post_code',$this->post_code,true);
		$criteria->compare('car_code',$this->car_code,true);
		$criteria->compare('town_code',$this->town_code,true);
		$criteria->compare('longitude',$this->longitude,true);
		$criteria->compare('latitude',$this->latitude,true);
		$criteria->compare('pinyin',$this->pinyin,true);
		$criteria->compare('initial_letter',$this->initial_letter,true);
		$criteria->compare('first_letter',$this->first_letter,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}